CORONADO ENTERPRISES C TUTOR This documentation and the accompanying software, including all of the example C programs and text files, are protected under United States copyright law to protect them from unauthorized commercialization. You are permitted to make archival copies of the software solely for the purpose of backing-up your copy of the distribution disk and protecting your investment from loss. You are permitted to use this software on as many computers as you have legal access to provided it is not in use on more than one computer at a time. As the registered purchaser of this software, you are permitted to use portions of any of the example programs for inclusion in your own software and will not be required to pay any royalties or fees for any distribution. WARRANTY The diskette and the accompanying documentation are warranted to be free of defects in materials and workmanship for a period of 60 days from purchase. The warranty is limited to replacement of any or all defective material. Coronado Enterprises will not be responsible for any loss of profit or any other commercial damage due to the use of this tutorial or the information contained within it. Gordon Dodrill - May 15, 1994 Copyright (c) 1988, 1989, 1994 Coronado Enterprises Coronado Enterprises 12501 Coronado Ave NE Albuquerque, New Mexico 87122 C TUTORIAL - TABLE OF CONTENTS Introduction Page I-1 Chapter 1 - Getting started Page 1-1 FIRSTEX.C The first example program 1-3 Chapter 2 - Program Structure Page 2-1 TRIVIAL.C The minimum program 2-1 WRTSOME.C Write some output 2-1 WRTMORE.C Write more output 2-2 ONEINT.C One integer variable 2-3 COMMENTS.C Comments in C 2-4 CPPCOMS.C C++ style comments 2-5 GOODFORM.C Good program style 2-6 UGLYFORM.C Bad program style 2-6 Chapter 3 - Program Control Page 3-1 WHILE.C The While loop 3-1 DOWHILE.C The Do-While loop 3-2 FORLOOP.C The For loop 3-2 IFELSE.C The If & If-Else construct 3-3 BREAKCON.C The Break & Continue 3-4 SWITCH.C The Switch construct 3-4 GOTOEX.C The Goto Statement 3-5 TEMPCONV.C The temperature conversion 3-6 DUMBCONV.C Poor program style 3-7 STYLE1.C Style illustrations 3-7 Chapter 4 - Assignment & Logical Compare Page 4-1 INTASIGN.C Integer assignments 4-1 MORTYPES.C More data types 4-2 LOTTYPES.C Lots of data types 4-4 COMBINE.C Combining different types 4-6 COMPARES.C Logical compares 4-7 CRYPTIC.C The cryptic constructs 4-11 Chapter 5 - Functions, variables, & prototyping Page 5-1 SUMSQRES.C First functions 5-1 SQUARES.C Return a value 5-3 FLOATSQ.C Floating returns 5-4 SCOPE.C Scope of variables 5-5 RECURSON.C Simple Recursion Program 5-9 BACKWARD.C Another Recursion Program 5-11 FLOATSQ2.C Float returns with prototypes 5-11 STYLE2.C Style illustrations 5-12 Chapter 6 - The C preprocessor Page 6-1 DEFINE.C Defines 6-1 MACRO.C Macros 6-3 IFDEF.C If defined 6-3 IFNDEF.C If not defined 6-4 DEBUGEX.C Debugging help 6-4 ENUM.C Enumerated type 6-6 Chapter 7 - Strings and Arrays Page 7-1 CHRSTRG.C Character Strings 7-1 STRINGS.C More Character strings 7-3 INTARRAY.C Integer Array 7-4 BIGARRAY.C Many Arrays 7-5 PASSBACK.C Getting data from Functions 7-5 MULTIARY.C Multidimensional arrays 7-6 Chapter 8 - Pointers Page 8-1 POINTER.C Simple Pointers 8-1 POINTER2.C More pointers 8-4 TWOWAY.C Twoway Function Data 8-6 FUNCPNT.C A pointer to a function 8-7 Chapter 9 - Standard Input/Output Page 9-1 SIMPLEIO.C Simplest standard I/O 9-1 SINGLEIO.C Single character I/O 9-4 BETTERIN.C Better form of single I/O 9-4 INTIN.C Integer input 9-6 STRINGIN.C String input 9-7 INMEM.C In memory I/O conversion 9-9 SPECIAL.C Standard error output 9-10 Chapter 10 - File Input/Output Page 10-1 FORMOUT.C Formatted output 10-1 CHAROUT.C Single character output 10-3 READCHAR.C Read single characters 10-4 READTEXT.C Read single words 10-5 READGOOD.C Better read and display 10-6 READLINE.C Read a full line 10-6 ANYFILE.C Read in any file 10-7 PRINTDAT.C Output to the printer 10-7 Chapter 11 - Structures Page 11-1 STRUCT1.C Minimum structure example 11-1 STRUCT2.C Array of structures 11-2 STRUCT3.C Structures with pointers 11-3 NESTED.C Nested structure 11-5 UNION1.C An example union 11-7 UNION2.C Another Union example 11-8 BITFIELD.C Bitfield example 11-9 STYLE3.H Style illustration 11-10 STYLE3.C Style illustration 11-11 Chapter 12 - Dynamic Allocation Page 12-1 DYNLIST.C Simple Dynamic Allocation 12-1 BIGDYNL.C Large Dynamic Allocation 12-5 DYNLINK.C Dynamic Linked List Program 12-6 Chapter 13 - Character and Bit Manipulation Page 13-1 UPLOW.C Upper/Lower Case Text 13-1 CHARCLAS.C Character Classification 13-1 BITOPS.C Logical Bit Operations 13-2 SHIFTER.C Bit Shifting Operations 13-2 Chapter 14 - Example programs Page 14-1 DOSEX.C DOS call examples 14-2 WHATNEXT.C Ask Question in Batch File 14-3 LIST.C Source Code Lister 14-4 VC.C Visual Calculator 14-4 ABOUT THE AUTHOR ----------------------------------------------------------------- The author of this tutorial began programming in 1961 using FORTRAN on an IBM 1620. Since then, most of his career has been involved with designing digital logic for satellite application. In 1983, being somewhat burned out with logic design, he began a study of some of the more modern programming languages and has since made a complete career shift to software development. After learning Pascal, C was studied, followed by Modula-2 and Ada, and more recently C++. Rather than simply learning the syntax of each new language, modern methods of software engineering were studied and applied to effectively utilize the languages. He is currently employed by a large research and development laboratory where he continues to study, teach, and apply the newer programming languages.